package com.macro.mall.product.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.product.service.PmProdStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 库存管理管理Controller
 */
@Controller
@Api(tags = "PmProdStockController", description = "出入库管理")
@RequestMapping("/prodStock")
public class PmProdStockController {

    @Autowired
    private PmProdStockService pmProdStockService;

    @ApiOperation(value = "增加库存")
    @RequestMapping(value = "/addStock", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<String> addStock(@RequestParam(value = "changeStock", defaultValue = "") Float changeStock,
                                                    @RequestParam(value = "stockId", defaultValue = "") Long stockId
    ) {
        try{
            pmProdStockService.addStock(stockId,changeStock);
        }catch (Exception e){
            return CommonResult.failed(e.getMessage());
        }
        return CommonResult.success("增加库存成功");
    }
//    @ApiOperation(value = "扣减库存")
//    @RequestMapping(value = "/deductStock", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<String> deductStock(@RequestParam(value = "changeStock", defaultValue = "") Float changeStock,
//                                            @RequestParam(value = "stockId", defaultValue = "") Long stockId,
//                                            @RequestParam(value = "orderId", defaultValue = "") String orderId
//    ) {
//        try{
//            pmProdStockService.deductStock(stockId,changeStock,orderId);
//        }catch (Exception e){
//            return CommonResult.failed(e.getMessage());
//        }
//        return CommonResult.success("扣减库存成功");
//    }
//    @ApiOperation(value = "回退库存")
//    @RequestMapping(value = "/rollbackStock", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<String> rollbackStock(@RequestParam(value = "changeStock") Long prodId,
//                                              @RequestParam(value = "stockId") Long skuInstId,
//                                              @RequestParam(value = "siteId") Integer siteId,
//                                              @RequestParam(value = "stockDate") String stockDate,
//                                              @RequestParam(value = "stockTime") String stockTime,
//                                              @RequestParam(value = "changeStock") Float changeStock,
//                                              @RequestParam(value = "orderId") String orderId
//    ) {
//        try{
//            pmProdStockService.rollbackStock(prodId, skuInstId, siteId, stockDate, stockTime, changeStock, orderId);
//        }catch (Exception e){
//            return CommonResult.failed(e.getMessage());
//        }
//        return CommonResult.success("回退库存成功");
//    }
//    @ApiOperation(value = "回退库存--简化版")
//    @RequestMapping(value = "/rollbackStockSimplify", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<String> rollbackStockSimplify(@RequestParam(value = "orderId") String orderId
//    ) {
//        try{
//            pmProdStockService.rollbackStockSimplify(orderId);
//        }catch (Exception e){
//            return CommonResult.failed(e.getMessage());
//        }
//        return CommonResult.success("回退库存成功");
//    }
}
